package com.jsoft.model;

import com.jsoft.dto.MenuItemDto;
import com.jsoft.model.core.BaseDao;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.List;

/**
 * Date: 26.09.13
 * Time: 17:54
 */

@Entity
@Table(name = "menu_items")
public class MenuItemDao extends BaseDao {
    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "recipe_id")
    private RecipeDao recipe;
    @Column(name = "price")
    private BigDecimal price;
    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "menu_items_disc_marg",
            joinColumns = @JoinColumn(name = "menu_item_id"),
            inverseJoinColumns = @JoinColumn(name = "dis_marg_id"))
    private List<DiscountMarginDao> disMargList;
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "menu_group_id")
    private MenuGroupDao menuGroup;

    public RecipeDao getRecipe() {
        return recipe;
    }

    public void setRecipe(RecipeDao recipe) {
        this.recipe = recipe;
    }

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public List<DiscountMarginDao> getDisMargList() {
        return disMargList;
    }

    public void setDisMargList(List<DiscountMarginDao> disMargList) {
        this.disMargList = disMargList;
    }

    public MenuGroupDao getMenuGroup() {
        return menuGroup;
    }

    public void setMenuGroup(MenuGroupDao menuGroup) {
        this.menuGroup = menuGroup;
    }

    public MenuItemDto wrapMenuItemDto() {
        MenuItemDto dto = new MenuItemDto();
        dto.setId(this.getObjectId());
        dto.setPrice(this.getPrice());
        return dto;
    }

    public MenuItemDao wrapMenuItemDao(MenuItemDto dto) {
        MenuItemDao dao = new MenuItemDao();
        dao.setPrice(dto.getPrice());
        return dao;
    }
}
